<template>
	<view class="p-10">
		<view class="card">
			<my-forms ref="valiForm" :model="valiFormData" :label-position="'top'" :formItem="formData">
				<template #state>
					<u-radio-group v-model="valiFormData.state" placement="row">
						<u-radio label="批准" :name="1"></u-radio>
						<u-radio style="margin-left: 10px" label="驳回" :name="0"></u-radio>
					</u-radio-group>
				</template>
			</my-forms>
			<u-button type="primary" shape="circle" text="确定" @click="submit"></u-button>
		</view>
	</view>
</template>
<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { reactive, ref, computed } from 'vue';
import { postNoticeApproveHandle, getNoticeApproveDetail } from '@/api/hidden-danger.js';
// 表单数据
let formData = computed(() => {
	return [
		{
			label: '批复意见',
			prop: 'state',
			required: true
		},
		{
			label: '受理人',
			prop: 'userName',
			disabled: true
		},
		{
			label: '申请人',
			prop: 'applyUserName',
			disabled: true
		},
		{
			label: '申请时间',
			prop: 'applyDate',
			disabled: true
		},
		{
			label: '申请原因',
			prop: 'applyInfo',
			type: 'textarea',
			disabled: true
		},
		{
			label: '驳回原因',
			type: 'textarea',
			required: true,
			prop: 'handleInfo',
			show: valiFormData.state === 0
		},
		{
			label: '整改资金',
			prop: 'changeMoney',
			type: 'number',
			maxlength: 9,
			show: valiFormData.state === 1
		},
		{
			itemType: 'select',
			type: 'GETuseList',
			label: '责任人',
			required: true,
			prop: 'dutyUserId',
			show: valiFormData.state === 1
		},
		{
			itemType: 'select',
			type: 'GETuseList',
			label: '督办人',
			required: true,
			prop: 'supervisionUserId',
			show: valiFormData.state === 1
		},
		{
			itemType: 'select',
			type: 'GETuseList',
			multiple: true,
			label: '验收人',
			required: true,
			prop: 'checkUserIds',
			show: valiFormData.state === 1
		}
	];
});
const valiForm = ref(null);
const valiFormData = reactive({
	state: 1
});
// 保存提交
const submit = () => {
	valiForm.value.$refs.refMyForm
		.validate()
		.then(async (res) => {
			const { code, msg } = await postNoticeApproveHandle(valiFormData);
			if (code == 200) {
				uni.showToast({
					icon: 'success',
					title: `批复成功`
				});
				uni.navigateBack({
					delta: 1 // 返回的页面数，如果是1则返回上一页
				});
			} else {
				uni.showToast({
					title: msg
				});
			}
		})
		.catch((err) => {
			console.log('err', err);
			uni.showToast({
				icon: 'error',
				title: err[0].errorMessage
			});
		});
};

onLoad((e) => {
	valiFormData.id = JSON.parse(e.id);
	getNoticeApproveDetail({
		id: valiFormData.id
	}).then((res) => {
		valiFormData.applyUserName = res.data.applyUserName;
		valiFormData.applyDate = res.data.applyDate;
		valiFormData.applyInfo = res.data.applyInfo;
		valiFormData.userName = res.data.userName;
		valiFormData.handleUser = res.data.handleUser;
		valiFormData.dutyUserId = res.data.dutyUserId;
	});
});
</script>
<style lang="scss" scoped></style>
